﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace ahdelivery.util
{
   public class JsonFileUtils
    {
        public static string Readjson(string fileName)
        {
            string filePath = Application.StartupPath+"\\" + fileName;
            if (!File.Exists(filePath))
            {
                return string.Empty;
            }
                using (System.IO.StreamReader file = System.IO.File.OpenText(filePath))
            {
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    JObject o = (JObject)JToken.ReadFrom(reader);
                    return o.ToString();
                }
            }
        }
        public static void WriteJson(string fileName,string json)
        {
            string filePath = Application.StartupPath + "\\" + fileName;
            System.IO.File.WriteAllText(filePath, json, Encoding.UTF8);
        }
    }
}
